﻿using System;
using System.Collections.Generic;
using Random = UnityEngine.Random;

namespace ZZQFrameWork.AI
{
    /// <summary>
    /// BT行为树状态
    /// </summary>
    public enum Enum_BTState
    {
        Failure,
        Success,
        Running
    }

    /// <summary>
    /// 行为树节点接口
    /// </summary>
    public interface IBehaviorTreeNode
    {
        Enum_BTState Proc(EntityParent owner);
    }

    /// <summary>
    /// 复合节点基类
    /// </summary>
    public class CompositeNode : IBehaviorTreeNode
    {
        /// <summary>
        /// 复合节点中所有的子节点集合
        /// </summary>
        protected List<IBehaviorTreeNode> childNodeList=new List<IBehaviorTreeNode>(); 

        public virtual Enum_BTState Proc(EntityParent owner)
        {
            return Enum_BTState.Success;
        }

        /// <summary>
        /// 添加节点
        /// </summary>
        /// <param name="node"></param>
        public void AddChild(IBehaviorTreeNode node)
        {
            childNodeList.Add(node);
        }

        /// <summary>
        /// 删除节点
        /// </summary>
        /// <param name="node"></param>
        public void RemoveChild(IBehaviorTreeNode node)
        {
            childNodeList.Remove(node);
        }

        /// <summary>
        /// 删除全部节点
        /// </summary>
        public void RemoveAllChild()
        {
            childNodeList.Clear();
        }
    }

    /// <summary>
    /// 装饰节点基类
    /// </summary>
    public class DecoratorNode : IBehaviorTreeNode
    {
        /// <summary>
        /// 给哪个节点进行装饰
        /// </summary>
        protected IBehaviorTreeNode child=null;

        /// <summary>
        /// 代理，设置需要装饰的技能
        /// </summary>
        /// <param name="node"></param>
        public void Proxy(IBehaviorTreeNode node)
        {
            child = node;
        }

        public virtual Enum_BTState Proc(EntityParent owner)
        {
            return child.Proc(owner);
        }
    }

    /// <summary>
    /// 条件节点基类
    /// </summary>
    public class ConditionNode : IBehaviorTreeNode
    {
        public virtual Enum_BTState Proc(EntityParent owner)
        {
            return Enum_BTState.Success;
        }
    }

    /// <summary>
    /// 行为节点基类
    /// </summary>
    public class ActionNode : IBehaviorTreeNode
    {
        public virtual Enum_BTState Proc(EntityParent owner)
        {
            return Enum_BTState.Success;
        }
    }

    /// <summary>
    /// 行为树根节点
    /// </summary>
    public class BehaviorTreeRoot : IBehaviorTreeNode
    {
        public IBehaviorTreeNode root;

        public Enum_BTState Proc(EntityParent owner)
        {
            return root.Proc(owner);
        }

        public void AddChild(IBehaviorTreeNode node)
        {
            root = node;
        }
    }

    public class BehaviorTree
    {
    }
}
